package com.faithnmn.phone;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.faithnmn.phone.model.PhoneItem;

public class PhoneItemAdapter extends ArrayAdapter<PhoneItem> {
	
	private LayoutInflater li;
	private List<PhoneItem> list;
	public PhoneItemAdapter(Context context, int resource,
			int textViewResourceId, List<PhoneItem> objects) {
		super(context, resource, textViewResourceId, objects);
		li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		list = objects;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if(convertView==null){
			convertView = li.inflate(R.layout.expandable_list_item, null);
			holder = new ViewHolder();
			holder.name = (TextView) convertView.findViewById(R.id.name);
			holder.phoneNo = (TextView) convertView.findViewById(R.id.phoneNo);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		holder.name.setText(list.get(position).phoneName);
		holder.phoneNo.setText(list.get(position).phoneNumber);
		
		return convertView;
	}
	
	private class ViewHolder{
		public TextView name;
		public TextView phoneNo;
	}
	
	@Override
	public int getCount() {
		return super.getCount();
	}
}
